package by.wind.drebedengi.datalayer;

import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;

import org.ksoap2.SoapEnvelope;
import org.ksoap2.serialization.MarshalHashtable;
import org.ksoap2.serialization.SoapObject;
import org.ksoap2.serialization.SoapSerializationEnvelope;
import org.ksoap2.transport.HttpTransportSE;



public abstract class AbstractAction {
	
	public abstract void loadData() throws Exception;
	
	public Object itsData;
	
	public Object loadData(String aMethodName, String anAction, HashMap<String, Object> aPropertyList) throws Exception{
		
		Object result = null;
	          SoapObject request = new SoapObject(Constants.NAMESPACE, aMethodName);
	          Iterator<Map.Entry<String, Object>> itr = aPropertyList.entrySet().iterator();
	          while (itr.hasNext()) {
	        	  String key = itr.next().getKey();
	        	  request.addProperty(key,aPropertyList.get(key));
	          }
	          

	          SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
	          envelope.setOutputSoapObject(request);
	          System.out.println("envelope:"+envelope.bodyOut);
	          HttpTransportSE androidHttpTransport = new HttpTransportSE(Constants.URL);
	          (new MarshalHashtable()).register(envelope);
	          androidHttpTransport.call(anAction, envelope);
	          result = envelope.getResponse();
			return result;
	}
	

}
